import {
	getSystem
} from '@/apis/system.js';
const system = {
	namespaced: true,
	state: {
		// false 为离线模式
		onlineStatus:uni.getStorageSync('onlineStatus') === '' ? true : uni.getStorageSync('onlineStatus'),
		// 系统设置
		system: JSON.parse(uni.getStorageSync('system') || '{}'), 
		// 0 未初始化， 1初始化成功 2加载失败 
		modelStatus: 0,
	},
	mutations: {
		setOnlineStatus(state, onlineStatus) {
			state.onlineStatus = onlineStatus;
			uni.setStorageSync('onlineStatus',onlineStatus);
		},
		setSystem(state, system) {
			state.system = system;
			uni.setStorageSync('system',JSON.stringify(system));
		},
	},

	actions: {
		getSystem({
			commit,
		}) {
			return new Promise((resolve, reject) => {
				getSystem().then(res => {
					commit('setSystem', res.data || {});
					resolve(res);
				}).catch(err => {
					reject(err);
				});
			});
		},

	}
};

export default system;
